package com.easy.controller;

import com.easy.bean.Category;
import com.easy.service.ICategoryService;
import com.easy.util.LayData;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("category")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;
    @RequestMapping("list")
    @ResponseBody
    public LayData getList(Page page,String text){
        List<Category> list=categoryService.getList(page,text);
        int count=categoryService.getCount(text);
        return new LayData(count,list);
    }

    @RequestMapping("random")
    @ResponseBody
    public LayData random(Integer count){
        List<Category> list=categoryService.random(count);
        return LayData.success(list);
    }
    @RequestMapping("delete")
    @ResponseBody
    public int delete(int id){
        return categoryService.delete(id);
    }

    @RequestMapping("getchildren")
    @ResponseBody
    public LayData getChildren(int id){
        return LayData.success(categoryService.getChildren(id));
    }
    @RequestMapping("add")
    @ResponseBody
    public int add(Category category){
       return categoryService.add(category);
    }

    @RequestMapping("edit")
    @ResponseBody
    public int edit(Category category){
        return categoryService.edit(category);
    }
}
